package com.tlias.exam.controller;

import com.tlias.exam.pojo.Goods;
import com.tlias.exam.pojo.PageResult;
import com.tlias.exam.pojo.Result;
import com.tlias.exam.pojo.QueryGoodsDTO;
import com.tlias.exam.service.GoogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 29 4月 2025 16:23
 */
@RestController
public class GoogController {
    @Autowired
    private GoogService googleService;

    /**
     * 条件分页查询
     *
     * @param queryGoodsDTO
     * @return
     */
    @GetMapping("/goods/page")
    public Result queryGoods(QueryGoodsDTO queryGoodsDTO) {
        PageResult pageResult = googleService.queryGoods(queryGoodsDTO);
        return Result.success(pageResult);
    }

    /**
     * 查询商品id
     */
    @GetMapping("/goods/{id}")
    public Result goodsXJ(@PathVariable Integer id) {
        Goods goods = googleService.getGoodsXJ(id);
        return Result.success(goods);
    }



    /**
     * 新增商品
     */
    @PostMapping("/goods")
    public Result addGoods(@RequestBody Goods goods) {
        googleService.addGoods(goods);
        return Result.success();
    }

    /**
     * 更新商品
     */
    @PutMapping("/goods")
    public Result updateGoods(@RequestBody Goods goods) {
        googleService.updateGoods(goods);
        return Result.success();
    }



    /**
     * 删除商品
     */
    @DeleteMapping("/goods/{ids}")
    public Result deleteGoods(@PathVariable List<Integer> ids) {
        googleService.deleteGoods(ids);
        return Result.success();
    }

}
